<?php

/**
 * @autdor aisyah
 * @copyright 2012
 */

include_once "header.php";
require_once "../../config/paging.php";

echo "<div class='container'>
<div class='row'>";

require_once "../dao/product_dao.php";

$modul=$_GET['modul'];
$id=$_GET['id'];
$breadcrump ="";

switch($modul){
    
    default :
    
        $p = new Paging;
        $batas = 5;
        $posisi = $p->cari_posisi($batas);
        
        echo "
            
            <table class='table table-bordered'>
                <tr><td colspan=8><a href='product_view.php?modul=tambah'><image src='../images/add.png'><strong>     Tambah Produk</strong></a></td></tr>
                <tr><th>ID</th><th>NAMA PRODUCT</th><th>TOKO PENJUAL</th><th>HARGA</th><th>GAMBAR</th><th>AKSI</th></tr>
                ";
				
        $product = new Product_Dao($class_db);
        
        $product->get_product(null,$posisi,$batas);      
        
        $data = $product->product;
        
        if($data!=null) {
            
           foreach($data as $produk) {
            
            $product->db->hasil = "";
            $product->db->show_Data('store','store_name',null,null,' store_id='.$produk->store_id);
            $hasil = $product->db->hasil;
            
            foreach($hasil as $store){
                $store = $store['store_name'];
            }
            
            $price = number_format($produk->price,2,',','.');
            
            echo "
                <tr>
                    <td>$produk->productdet_id</td>
                    <td><a href='product_view.php?modul=detil&id=$produk->productdet_id'>$produk->product_name</a></td> 
                    <td>$store</td>
					<td>Rp. $price</td>
                    <td><div class=span1><image class=thumbnail src='../../images/produk/$produk->image' width=90 heigth=30></div></td>                    
                    <td><a href='product_view.php?modul=ubah&id=$produk->productdet_id'><image src='../images/edit.gif'>Edit</a> | 
						<a href='product_aksi.php?modul=hapus&id=$produk->productdet_id'><image src='../images/delete.gif'>Delete</a>
					</td>
                </tr>
                ";        
            
            } 
        }else{
            echo "<tr><td colspan=5 align=center>DATA TIDAK DITEMUKAN</td></tr>";
        }
        
        //print_r($data);        {
        
        
        
         
        echo "            
            </table>
            ";
            
        $product->product = null;
        
        $product->get_product();
            
        $jmldata = count($product->product);
        
        $jml_halaman = $p->jml_halaman($jmldata,$batas);
        //print_r($jml_halaman);
        
        $link_halaman = $p->navHalaman($modul,$_GET['halaman'],$jml_halaman);
        
        echo $link_halaman;
        
    break;    
    
    case "ubah":
    
        $produk = new Product_Dao($class_db);
        
        $produk->get_product($id);
        
        $product = $produk->product;
        
        foreach($product as $data) {
            
            $produk->db->hasil = "";
            $produk->db->show_Data('store','store_name',null,null,' store_id='.$data->store_id);
            $hasil = $produk->db->hasil;
            
            foreach($hasil as $store){
                $store = $store['store_name'];
            }
            
            $price=number_format($data->price,2,',','.');
        
        echo "
            <form method='POST' action='product_aksi.php?modul=ubah' enctype='multipart/form-data'>
            <input type='hidden' name='id' value=$data->productdet_id>
            <table>
                <tr><td colspan=12 align='center'><h1>Ubah Data Produk</h1></td></tr>
					<tr><td>Nama Produk</td><td><input type='text' name='product_name' value='$data->product_name'></td></tr>
					<tr><td>Deskripsi</td><td><textarea name='description' rows=10>$data->description</textarea></td></tr>
					<tr><td>Nama Toko</td><td><input type='text' name='store' value='$store' readonly=readonly></td></tr>
                    <tr><td>Harga</td><td><input type='text' name='price' value='$data->price'></td></tr>             
                    <tr><td>Gambar</td><td><image src='$data->image'></td></tr>
                    <tr><td></td><td><input type='file' name='image' ></td></tr>                   
                    <tr><td colspan=2><input class='btn btn-primary' type=submit value=Simpan><input class='btn btn-primary' type=button value=Batal onclick=self.history.back()></td></tr>
				</table>
            </form>
            ";
            
            }
    
    break;
    
    case "detil":
    
        $produk = new Product_Dao($class_db);
        
        $produk->get_product($id);
        
        $product = $produk->product;
        
        foreach($product as $data) {
            
            echo "
            <table>
                <tr><td colspan=8 align='center'><h1>Data Produk</h1></td></tr>
					<tr><td>Nama Produk</td><td>$data->product_name</td></tr>
					<tr><td>Deskripsi</td><td>$data->description</td></tr>					
                    <tr><td>Toko</td><td>$data->store_id</td></tr>                    
                    <tr><td>Gambar</td><td><image src='$data->image'></td></tr>                    
                    <tr><td colspan=2><input type=button class='btn btn-primary' value='UBAH' onclick=\"window.location.href='product_view.php?modul=ubah&id=$data->productdet_id';\">
                    <input class='btn btn-primary' type=button value=Kembali onclick=self.history.back()></td></tr>
				</table>
            ";
            
            }
    
    break;

echo "</div>";
echo "</div>";
 
    
}